package cn.yunhe.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.yunhe.biz.IProvienceMessageBiz;
import cn.yunhe.biz.ProvienceMessageBizImpl;
import cn.yunhe.entity.ProvienceMessage;



/**
 * Servlet implementation class DoUser
 */
public class DoPm extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DoPm() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
		HttpSession session = request.getSession();
		PrintWriter out =response.getWriter();
		IProvienceMessageBiz ipmb = new ProvienceMessageBizImpl();
		
		String opt = request.getParameter("opt");
		if("add".equals(opt)){
			String p_name = request.getParameter("p_name");
			String p_date = request.getParameter("p_date");
			String p_cont = request.getParameter("p_cont");
			String sp_one = request.getParameter("p_one");
			String sp_two = request.getParameter("p_two");
			String p_wri = request.getParameter("p_wri");
			
			int p_one = Integer.parseInt(sp_one);
			int p_two = Integer.parseInt(sp_two);
			
			
			ProvienceMessage pm = new ProvienceMessage();
			pm.setP_name(p_name);
			pm.setP_date(p_date);
			pm.setP_cont(p_cont);
			pm.setP_one(p_one);
			
			boolean r = ipmb.insert(p_name, p_date, p_cont, p_one, p_two, p_wri);
			response.sendRedirect("DoBackstage?opt=getProvinces");
		}else if("update".equals(opt)){
			String sp_id = request.getParameter("p_id");
			String p_name = request.getParameter("p_name");
			String p_date = request.getParameter("p_date");
			String p_cont = request.getParameter("p_cont");
			String sp_one = request.getParameter("p_one");
			String sp_two = request.getParameter("p_two");
			String p_wri = request.getParameter("p_wri");
			int p_id = Integer.parseInt(sp_id);
			int p_one = Integer.parseInt(sp_one);
			int p_two = Integer.parseInt(sp_two);
			
			
			
			boolean r= ipmb.update(p_id, p_name, p_date, p_cont, p_one, p_two, p_wri, p_id);
			response.sendRedirect("DoBackstage?opt=getProvinces");
		}else if("del".equals(opt)){
			String sp_id = request.getParameter("pid");
			int p_id = Integer.parseInt(sp_id);
			
			boolean r = ipmb.del(p_id);
			response.sendRedirect("DoBackstage?opt=getProvinces");
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
